import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2025-07-16
 * Time: 22:41
 */
public class Test56 {
    static List<List<Integer>> ret;
    static List<Integer> path;
    static boolean[] check;
    static public List<List<Integer>> permute(int[] num) {
        ret  = new ArrayList<>();
        path = new ArrayList<>();
        check = new boolean[num.length];
        dfs(num);
        return ret;
    }

    static void dfs(int[] num) {
        if(path.size() == num.length) {
            ret.add(new ArrayList<>(path));
            return;
        }

        for(int i = 0; i < num.length; i++) {
            if(check[i] == false) {
                path.add(num[i]);
                check[i] = true;
                dfs(num);
                // 回溯
                check[i] = false;
                path.remove(path.size()-1);
            }
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] num = new int[n];
        for(int i = 0; i < n; i++) {
            num[i] = sc.nextInt();
        }
        List<List<Integer>> ret = permute(num);
        System.out.println(ret);
    }


}
